Make gdk_window_get_toplevel() for CHILD window with root as parent
authorAlexander Larsson <alexl@redhat.com>
Wed, 28 Jan 2009 15:37:56 +0000 (16:37 +0100)
committerAlexander Larsson <alex@localhost.localdomain>
Thu, 2 Apr 2009 08:15:29 +0000 (10:15 +0200)
Having GDK_WINDOW_CHILD windows with root as the parent apparently works,
and metacity uses it. The current gdk_window_get_toplevel() returns the
root window for that, which is wrong, so we check that explicitly.

gdk/gdkwindow.c

index 36cb4ef5bb6aa8da81edc16aab00d9a7c5fc08e0..978dd2e6098350c3c06e40f1721ac7f1de38d8a3 100644 (file)
@@ -1662,6 +1662,10 @@ gdk_window_get_parent (GdkWindow *window)
  * @window: a #GdkWindow
  * 
  * Gets the toplevel window that's an ancestor of @window.
+ *
+ * Any window type but %GDK_WINDOW_CHILD is considered a
+ * toplevel window, as is a %GDK_WINDOW_CHILD window that
+ * has a root window as parent. 
  * 
  * Return value: the toplevel window containing @window
  **/
@@ -1673,8 +1677,14 @@ gdk_window_get_toplevel (GdkWindow *window)
   g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
 
   obj = (GdkWindowObject *)window;
+  
   while (GDK_WINDOW_TYPE (obj) == GDK_WINDOW_CHILD)
-    obj = (GdkWindowObject *)obj->parent;
+    {
+      if (obj->parent == NULL ||
+         GDK_WINDOW_TYPE (obj->parent) == GDK_WINDOW_ROOT)
+       break;
+      obj = obj->parent;
+    }
   
   return GDK_WINDOW (obj);
 }